package com.design.absfactory;

import com.design.absfactory.factory.CpuFactory;
import com.design.absfactory.factory.MainboardFactory;
import com.design.absfactory.inter.AbstractFactory;
import com.design.absfactory.inter.Cpu;
import com.design.absfactory.inter.Mainboard;

/**
 * Created by Administrator on 2016/8/27.
 */
public class ComputerEngineer {

    // 简单工厂
    private Cpu cpu = null;
    private Mainboard mainboard = null;



    // 简单工厂
    public void makeComputer(int cputype, int mainboard) {

        prepareHardwares(cputype, mainboard);
    }


    private void prepareHardwares(int cputype, int mainboard) {
        this.cpu = CpuFactory.createCpu(cputype);
        this.mainboard = MainboardFactory.createMainboard(mainboard);

        this.cpu.calculate();
        this.mainboard.installCPU();
    }


    // 抽象工厂
    public void makeComputer(AbstractFactory factory) {
        prepareHardwares(factory);
    }

    private void prepareHardwares(AbstractFactory factory) {
        this.cpu = factory.createCpu();
        this.mainboard = factory.createMainboard();

        this.cpu.calculate();
        this.mainboard.installCPU();
    }
}
